<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="/js/jquery-3.5.0.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/components.css">
    <link rel="stylesheet" href="/css/login.css">
    <title>用户注册</title>
</head>
<body class="login">
<div class="content">
    <h3>用户登录</h3>
    <div>
        <label class="control-label" for="telephone">手机号</label>
        <div>
            <input class="form-control" type="text" name="telephone" id="telephone">
        </div>
        <label class="control-label" for="password">密码</label>
        <div>
            <input class="form-control" type="password" name="password" id="password">
        </div>
        <div class="form-actions">
            <button class="btn red-thunderbird" type="submit" id="login">点击登录</button>
        </div>
    </div>
</div>


</body>
<script>
    $(function () {
        $("#login").on("click",function () {
            $.ajax({
                type:"POST",
                contentType: "application/x-www-form-urlencoded",
                url:"/user/login",
                data:{
                  "telephone":$("#telephone").val(),
                  "password":$("#password").val(),
                },
                success:function (data) {
                    if(data.status === "success"){
                        alert("登录成功")
                        console.log(data)
                        var uuidToken = data.data.uuidToken
                        window.localStorage["uuidToken"] = uuidToken
                        var refer = document.referrer
			                  if (refer.split('/')[3]===""){
                            window.location.href = "/html/item_list.html"
                        }else {
                            window.location.href = refer
                        }
                    }else {
                        alert("登陆失败：" + data.data.errorMsg)
                    }
                },
                error:function (data) {
                    alert("登陆失败：" + data.responseText)
                }
            })
        })
    })
</script>
</html>
